package generator.service.impl;

import generator.mapper.SysUserMapper;
import generator.pojo.SysUser;
import generator.service.SysUserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class SysUserServiceImpl implements SysUserService {
    SysUserMapper userMapper;
    @Test
    public void a() throws IOException {

        //1. 加载mybatis_config.xml映射文件
        String url ="mybatis-config.xml";
        InputStream is = Resources.getResourceAsStream(url);

        SqlSession session =null;
        SqlSessionFactory fac= new SqlSessionFactoryBuilder().build(is);

        session =fac.openSession();
        SysUser count = session.getMapper(SysUserMapper.class).selectByPrimaryKey(1L);
        System.out.println("总数: "+count);

        session.close();




    }

    public SysUserMapper getUserMapper() {
        return userMapper;
    }

    public void setUserMapper(SysUserMapper userMapper) {
        this.userMapper = userMapper;
    }

    @Override
    public int getCount() throws IOException {
        return 0;
    }
}
